local thbattle__xiaoting_bian = fk.CreateSkill {

  name = "thbattle__xiaoting_bian",

  tags = {},

}



thbattle__xiaoting_bian:addEffect("active", {
  prompt = "#thbattle__xiaoting_bian-active",
  anim_type = "offensive",
  max_phase_use_time = 1,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select) and not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_num = 1,
  target_filter =function (self, player, to_select, selected, selected_cards, card, extra_data)
     return #selected == 0 and to_select ~= player
  end,
  can_use = function(self, player, card, extra_data)
    return not player:isNude() and player:usedSkillTimes(thbattle__xiaoting_bian.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards, thbattle__xiaoting_bian.name, player, player)
    THB_Utility.setStatusMark(target, "@@thbattle__xiaoting_bian-turn")
    local target_bool = true
    for _, p in ipairs(room.alive_players) do
      if p.hp < target.hp then
        target_bool = false
      end
    end
    if target_bool then
      local choice
      if target:isNude() then
        choice = "摸一张牌"
      else
        choice = room:askToChoice(player,{
          choices={ "摸一张牌", "弃置其一张牌" },
          skill_name=thbattle__xiaoting_bian.name
        }) 
      end
      if choice == "摸一张牌" then
        player:drawCards(1, thbattle__xiaoting_bian.name)
      else
        local discard = room:askForCardChosen(player, target, "he", thbattle__xiaoting_bian.name,
          "#thbattle__xiaoting_bian-discard")
        room:throwCard(discard, thbattle__xiaoting_bian.name, target, player)
      end
    end
  end,
})

thbattle__xiaoting_bian:addEffect("distance", {
  fixed_func = function(self, from, to)
    if from and to and from.phase ~= Player.NotActive and to:getMark("@@thbattle__xiaoting_bian-turn") > 0 then
      return 1
    end
  end,
})

return thbattle__xiaoting_bian
